home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- CPixelWorld.c
-
- The PixelWorld Class
-
- The CPixelWorld class is a subclass of CBitMap designed to maintain a
- color offscreen drawing environment using the standard conventions of
- Color QuickDraw. An offscreen color graphics device (GDevice) and an
- offscreen color graphics port (CGrafPort) are used to maintain this
- offscreen world. This implementation supports 1,2,4 and 8 bit pixel
- depths. Pixel depths of 16 and 32 bits are currently not supported.
-
- This implementation does not depend upon any 32-Bit QuickDraw features.
- Future versions of the CPixelWorld class will provide support for pixel
- depths of 16 and 32 bits, and for GWorlds under 32-Bit QuickDraw.
-
- SUPERCLASS = CBitMap
-
- This implementation is based in part on material copyrighted by
- Symantec Corporation and Apple Computer, Inc.
-
- Copyright © 1992 Vincent R. Vann, Jr. All rights reserved.
-
- Version 1.1 Changes:
- [
- - CopyFrom and CopyTo methods were modified so that the foreground
- and background colors are set to black and white before calling
- CopyBits. This ensures that the PixelWorld image is copied with
- the proper colors. The foreground and background colors of the
- current CGrafPort are preserved by these methods.
- ]
-
- Version 1.2 Changes:
- [
- - added new instance variables saveFgColor and saveBgColor.
- - implemented new methods SaveColors, RestoreColors,
- CopyFromColors, and CopyToColors.
- - changed CopyFrom and CopyTo methods to use these color routines.
- - see comments for CopyFromColors and CopyToColors for information
- about how to colorize your image.
- ]
-
- ******************************************************************************/
-
- #include "CPixelWorld.h"
- #include "CDesktop.h"
- #include "Exceptions.h"
- #include "Global.h"
- #include "LongQD.h"
- #include "TCLUtilities.h"
-
-
- /**** C O N S T R U C T I O N / D E S T R U C T I O N M E T H O D S ****/
-
-
- /******************************************************************************
- IPixelWorld
-
- Initialize a PixelWorld object
- ******************************************************************************/
-
- void CPixelWorld::IPixelWorld(
- short aPixelDepth, /* Pixel depth of world in bits */
- Rect *aBoundsRect, /* Bounds rectangle of world */
- CTabHandle aColorTable, /* ColorTable for world image */
- Handle aPixelImage, /* Handle to pixel image for world */
- short aRowBytes) /* Row bytes of pixel image */
- {
- /* Initialize instance variables of CBitMap superclass */
-
- macPort = NULL;
- savePort = NULL;
- macBitMap = NULL;
- xferMode = srcCopy;
-
- /* Initialize instance variables of CPixelWorld class */
-
- worldIsOK = FALSE; /* TRUE if initialized successfully */
- worldHasColor = gSystem.hasColorQD; /* TRUE if have Color QuickDraw */
- worldHas32BitQD = FALSE; /* TRUE if have 32-Bit QuickDraw */
- worldOwnsPixels = FALSE; /* TRUE if world owns pixel image */
- worldPixelsLocked = FALSE; /* TRUE if pixel image is locked */
-
- worldDepth = 0;
-
- worldBounds.left = 0;
- worldBounds.top = 0;
- worldBounds.right = 0;
- worldBounds.bottom = 0;
-
- worldColors = NULL;
- worldDevice = NULL;
- worldPort = NULL;
- worldPixels = NULL;
-
- saveDevice = NULL;
-
- if (!worldHasColor)
- IPixelWorldBW( aPixelDepth, aBoundsRect, aPixelImage, aRowBytes);
- else
- IPixelWorldColor( aPixelDepth, aBoundsRect, aColorTable, aPixelImage, aRowBytes);
- }
-
-
- /******************************************************************************
- IPixelWorldBW
-
- Initialize a black and white pixel world
- ******************************************************************************/
-
- void CPixelWorld::IPixelWorldBW(
- short aPixelDepth, /* Pixel depth of world in bits */
- Rect *aBoundsRect, /* Bounds rectangle of world */
- Handle aPixelImage, /* Handle to pixel image for world */
- short aRowBytes) /* Row bytes of pixel image */
- {
- GrafPtr theSavedPort;
- Boolean theSavedAlloc;
- short rowBytes;
- long bytes, width, height;
-
- /***
- *** Check for a valid pixel depth
- ***/
-
- if (aPixelDepth != 1) return;
-
- /***
- *** Create the offscreen bitmap
- ***/
-
- width = aBoundsRect->right - aBoundsRect->left;
- height = aBoundsRect->bottom - aBoundsRect->top;
-
- if (aPixelImage != NULL && aRowBytes != 0)
- rowBytes = aRowBytes;
- else
- rowBytes = ((width * aPixelDepth + 31) / 32 ) * 4;
-
- bytes = height * rowBytes;
-
- theSavedAlloc = SetAllocation( kAllocCanFail);
- macBitMap = (BitMap *) NewPtrClear(sizeof(BitMap) + bytes);
- SetAllocation( theSavedAlloc);
-
- FailNIL( macBitMap);
-
- macBitMap->baseAddr = (Ptr) (macBitMap + 1);
- macBitMap->rowBytes = rowBytes;
- macBitMap->bounds = *aBoundsRect;
-
- /***
- *** Copy the existing pixel image into the offscreen bitmap
- ***/
-
- if (aPixelImage != NULL && aRowBytes != 0)
- {
- long n;
-
- n = GetHandleSize(aPixelImage);
- if (n > 0 && MemError() == noErr)
- {
- if (n > bytes) n = bytes;
-
- HLock( aPixelImage);
- BlockMove( (Ptr) *aPixelImage, macBitMap->baseAddr, n);
- HUnlock( aPixelImage);
- }
- }
-
- /***
- *** Create the offscreen graphics port
- ***/
-
- theSavedAlloc = SetAllocation( kAllocCanFail);
- macPort = (GrafPtr) NewPtrClear( sizeof(GrafPort));
- SetAllocation( theSavedAlloc);
-
- FailNIL( macPort);
-
- GetPort( &theSavedPort);
-
- OpenPort( macPort);
- SetPort( macPort);
-
- SetPortBits( macBitMap);
- macPort->portRect = *aBoundsRect;
- RectRgn( macPort->visRgn, aBoundsRect);
- RectRgn( macPort->clipRgn, aBoundsRect);
-
- SetPort( theSavedPort);
-
- CView::ForceNextPrepare();
-
- worldIsOK = TRUE;
- }
-
-
- /******************************************************************************
- IPixelWorldColor
-
- Initialize a color pixel world
- ******************************************************************************/
-
- void CPixelWorld::IPixelWorldColor(
- short aPixelDepth, /* Pixel depth of world in bits */
- Rect *aBoundsRect, /* Bounds rectangle of world */
- CTabHandle aColorTable, /* ColorTable for world image */
- Handle aPixelImage, /* Handle to pixel image for world */
- short aRowBytes) /* Row bytes of pixel image */
- {
- GDHandle theSavedDevice;
- GrafPtr theSavedPort;
- Boolean theSavedAlloc;
-
- /***
- *** Check for a valid pixel depth
- ***/
-
- if (aPixelDepth != 1 && aPixelDepth != 2 && aPixelDepth != 4 && aPixelDepth != 8)
- return;
-
- /***
- *** Set worldDepth and worldBounds instance variables
- ***/
-
- worldDepth = aPixelDepth;
-
- worldBounds.left = aBoundsRect->left;
- worldBounds.top = aBoundsRect->top;
- worldBounds.right = aBoundsRect->right;
- worldBounds.bottom = aBoundsRect->bottom;
-
- /***
- *** Create the world color table
- ***/
-
- if (aColorTable != NULL) /* Copy the color table */
- {
- OSErr error;
-
- theSavedAlloc = SetAllocation( kAllocCanFail);
- error = HandToHand( &aColorTable);
- SetAllocation( theSavedAlloc);
-
- FailOSErr(error);
-
- worldColors = aColorTable;
- }
- else /* Use standard color table for the pixel depth */
- {
- worldColors = GetCTable( aPixelDepth);
- }
-
- /***
- *** Create the world pixel image
- ***/
-
- if (aPixelImage != NULL && aRowBytes != 0) /* Use the existing pixel image */
- {
- HUnlock( aPixelImage);
-
- worldPixels = aPixelImage;
- worldOwnsPixels = FALSE; /* We don't own the pixel image */
- }
- else /* Create a new blank pixel image */
- {
- long width, height;
-
- width = aBoundsRect->right - aBoundsRect->left;
- height = aBoundsRect->bottom - aBoundsRect->top;
-
- aRowBytes = ((width * aPixelDepth + 31) / 32 ) * 4;
-
- theSavedAlloc = SetAllocation( kAllocCanFail);
- aPixelImage = NewHandleClear( height * aRowBytes);
- SetAllocation( theSavedAlloc);
-
- FailNIL( aPixelImage);
-
- worldPixels = aPixelImage;
- worldOwnsPixels = TRUE; /* We own the pixel image, and must dispose of it */
- }
-
- /***
- *** Create the offscreen graphics device
- ***/
-
- worldDevice = NewGDevice( 0, -1L);
- FailNIL( worldDevice);
-
- HLock(worldDevice);
- {
- GDPtr gdev = *worldDevice;
-
- gdev->gdID = 0;
- gdev->gdType = clutType;
- gdev->gdResPref = 4;
- gdev->gdSearchProc = NULL;
- gdev->gdCompProc = NULL;
- gdev->gdFlags = (1<<gdDevType) | (1<<ramInit) | (1<<noDriver) | (1<<screenActive);
- gdev->gdRect = *aBoundsRect;
-
- HLock(gdev->gdPMap);
- {
- PixMapPtr pmap = *gdev->gdPMap;
-
- pmap->baseAddr = NULL;
- pmap->rowBytes = aRowBytes | 0x8000;
- pmap->bounds = *aBoundsRect;
- pmap->pixelSize = aPixelDepth;
- pmap->cmpCount = 1;
- pmap->cmpSize = aPixelDepth;
-
- DisposCTable(pmap->pmTable);
- pmap->pmTable = worldColors;
- }
- HUnlock(gdev->gdPMap);
- }
- HUnlock(worldDevice);
-
- MakeITable( worldColors, (**worldDevice).gdITable, 4);
- FailOSErr( QDError());
-
- /***
- *** Create the offscreen graphics port
- ***/
-
- theSavedAlloc = SetAllocation( kAllocCanFail);
- worldPort = (CGrafPtr) NewPtrClear( sizeof(CGrafPort));
- SetAllocation( theSavedAlloc);
-
- FailNIL( worldPort);
-
- theSavedDevice = GetGDevice();
- GetPort( &theSavedPort);
-
- SetGDevice( worldDevice);
- OpenCPort( worldPort);
-
- worldPort->portRect = *aBoundsRect;
- RectRgn( worldPort->visRgn, aBoundsRect);
- RectRgn( worldPort->clipRgn, aBoundsRect);
-
- SetGDevice( theSavedDevice);
- SetPort( theSavedPort);
-
- CView::ForceNextPrepare();
-
- worldIsOK = TRUE;
- }
-
-
- /******************************************************************************
- Dispose {OVERRIDE}
-
- Dispose of a PixelWorld
- ******************************************************************************/
-
- void CPixelWorld::Dispose()
- {
- if (worldPort != NULL)
- {
- ClosePort( worldPort); /* Close the color graphics port */
- DisposPtr( worldPort); /* Dispose of color graphics port */
- }
-
- if (worldDevice != NULL)
- {
- DisposGDevice( worldDevice); /* Dispose of gDevice and colorTable */
- }
- else
- {
- DisposCTable( worldColors); /* Dispose of the colorTable */
- }
-
- if (worldPixels != NULL && worldOwnsPixels)
- {
- DisposHandle( worldPixels); /* Dispose of pixel image */
- }
-
- /* The inherited method disposes of black & white pixel worlds */
-
- inherited::Dispose();
- }
-
-
- /******************************************************************************
- WorldIsOK
-
- Return TRUE if world has been initialized successfully, FALSE otherwise.
- ******************************************************************************/
-
- Boolean CPixelWorld::WorldIsOK()
- {
- return( worldIsOK);
- }
-
-
- /******************************************************************************
- GetPixelDepth
-
- Return the bounding rectangle of a PixelWorld. This rectangle defines
- the size and coordinate system of the PixelWorld.
- ******************************************************************************/
-
- short CPixelWorld::GetPixelDepth()
- {
- return (worldDepth);
- }
-
-
- /******************************************************************************
- GetBounds {OVERRIDE}
-
- Return the bounding rectangle of a PixelWorld. This rectangle defines
- the size and coordinate system of the PixelWorld.
- ******************************************************************************/
-
- void CPixelWorld::GetBounds(
- LongRect *theBounds)
- {
- *theBounds = worldBounds;
- }
-
-
- /******************************************************************************
- GetRowBytes
-
- Return row byte length for the offscreen image.
- ******************************************************************************/
-
- short CPixelWorld::GetRowBytes()
- {
- short rowBytes;
-
- if (!worldIsOK) return (0);
-
- if (worldHasColor) /* World has color */
- {
- rowBytes = (**worldPort->portPixMap).rowBytes;
- }
- else /* World is black and white */
- {
- rowBytes = macBitMap->rowBytes;
- }
-
- rowBytes &= 0x7FFF;
- return (rowBytes);
- }
-
-
- /******************************************************************************
- PixelIsBlack {OVERRIDE}
-
- Determine whether the pixel at the specified coordinates is black.
- Returns FALSE if the pixel is not black or it is not within the
- world bounds rectangle.
- ******************************************************************************/
-
- Boolean CPixelWorld::PixelIsBlack(
- LongPt *pixelPos)
- {
- RGBColor color;
-
- if (!worldIsOK) return (FALSE);
-
- if (worldHasColor) /* World has color */
- {
- if (GetPixelColor( pixelPos, &color) == TRUE) /* Inside */
- {
- if (color.red == 0 && color.green == 0 && color.blue == 0)
- return (TRUE);
- else
- return (FALSE);
- }
- else
- {
- return (TRUE); /* Pixel is outside and must be black */
- }
- }
- else /* World is black and white */
- {
- return (inherited::PixelIsBlack(pixelPos));
- }
- }
-
-
- /******************************************************************************
- GetPixelColor
-
- Determines the color of the pixel at the specified coordinates.
- Returns FALSE if the point is not within the PixelWorld.
-
- *** IMPORTANT ***
-
- The offscreen pixel world must be active and the worldPixels
- must be locked for this method to work properly. Therefore,
- always send a BeginDrawing message before calling GetPixelColor().
- When you are finished getting all the pixel colors you need,
- then send the EndDrawing message to restore the previous
- drawing environment.
- ******************************************************************************/
-
- Boolean CPixelWorld::GetPixelColor(
- LongPt *pixelPos,
- RGBColor *color)
- {
- LongRect bounds = worldBounds;
-
- if (!worldIsOK) return (FALSE);
-
- if (!PtInLongRect( pixelPos, &bounds)) /* Pixel is OUTSIDE bounds rectangle */
- return (FALSE);
-
- if (worldHasColor) /* World has color */
- {
- if (worldPixelsLocked)
- GetCPixel((short) pixelPos->h, (short) pixelPos->v, color); /* Get color */
- else
- color->red = color->green = color->blue = 0; /* Black */
- }
- else /* World is black and white */
- {
- if (inherited::PixelIsBlack(pixelPos))
- color->red = color->green = color->blue = 0; /* Black */
- else
- color->red = color->green = color->blue = 65535; /* White */
- }
-
- return(TRUE); /* Pixel is INSIDE bounds rectangle */
- }
-
-
- /******************************************************************************
- GetHandleToPixels
-
- Return a handle to the pixel image. The handle is only valid
- when the offscreen world is in color. If the offscreen world
- is in black and white, a NULL handle is returned.
- ******************************************************************************/
-
- Handle CPixelWorld::GetHandleToPixels()
- {
- return( worldPixels);
- }
-
-
- /******************************************************************************
- GetPointerToPixels
-
- Return a pointer to the pixel image. Works for color and black/white
- images as well.
- ******************************************************************************/
-
- Ptr CPixelWorld::GetPointerToPixels()
- {
- if (!worldIsOK) return (NULL);
-
- if (worldHasColor) /* World has color */
- {
- return( (Ptr) *worldPixels);
- }
- else /* World is black and white */
- {
- return( (Ptr) macBitMap->baseAddr);
- }
- }
-
-
- /******************************************************************************
- SetBoundsOrigin {OVERRIDE}
-
- Set the coordinates of the top left corner of the bounds of a
- PixelWorld. This changes the coordinate system of the PixelWorld.
- Note that the visRgn and clipRgn of the PixelWorld are reset.
- ******************************************************************************/
-
- void CPixelWorld::SetBoundsOrigin(
- short hOrigin,
- short vOrigin)
- {
- Rect bounds;
-
- if (!worldIsOK) return;
-
- bounds.left = hOrigin;
- bounds.top = vOrigin;
- bounds.right = hOrigin + (worldBounds.right - worldBounds.left);
- bounds.bottom = vOrigin + (worldBounds.bottom - worldBounds.top);
-
- worldBounds.left = bounds.left;
- worldBounds.top = bounds.top;
- worldBounds.right = bounds.right;
- worldBounds.bottom = bounds.bottom;
-
- if (worldHasColor) /* World has color */
- {
- HLock(worldDevice);
- {
- GDPtr gdev = *worldDevice;
-
- (**gdev->gdPMap).bounds = bounds;
- gdev->gdRect = bounds;
- }
- HUnlock(worldDevice);
-
- (**worldPort->portPixMap).bounds = bounds;
- worldPort->portRect = bounds;
- RectRgn( worldPort->visRgn, &bounds);
- RectRgn( worldPort->clipRgn, &bounds);
- }
- else /* World is black and white */
- {
- macBitMap->bounds = bounds;
- macPort->portBits.bounds = bounds;
- macPort->portRect = bounds;
-
- RectRgn( macPort->visRgn, &bounds);
- RectRgn( macPort->clipRgn, &bounds);
- }
- }
-
-
- /******************************************************************************
- BeginDrawing {OVERRIDE}
-
- *** IMPORTANT ***
-
- Always send this message before performing any drawing to the
- offscreen pixel world. This function saves the current GDevice
- and GrafPort, activates the worldDevice and worldPort, and sends
- the message LockWorld( TRUE) to lock down the pixel image.
-
- If you do not call BeginDrawing() before drawing to the offscreen
- world, the PixMaps of the worldDevice and worldPort will have NULL
- baseAddr pointers and any drawing calls will probably cause a
- CRASH since low memory addresses will be overwritten !!!!!!
- ******************************************************************************/
-
- void CPixelWorld::BeginDrawing()
- {
- ActivateWorld();
- }
-
-
- /******************************************************************************
- EndDrawing {OVERRIDE}
-
- *** IMPORTANT ***
-
- Always send this message after performing any drawing to the
- offscreen pixel world. This function resets the port to the
- way it was before the BeginDrawing message. It restores the
- saved GDevice and GrafPort, and unlocks the pixel image.
- ******************************************************************************/
-
- void CPixelWorld::EndDrawing()
- {
- DeactivateWorld();
- }
-
-
- /******************************************************************************
- ActivateWorld
-
- Activates the offscreen pixel world so that all drawing will take
- place in the offscreen graphics port. The currently active graphics
- device and port are saved so they can be restored later.
- ******************************************************************************/
-
- void CPixelWorld::ActivateWorld()
- {
- if (!worldIsOK) return;
-
- if (worldHasColor) /* World has color */
- {
- saveDevice = GetGDevice();
- GetPort( &savePort);
-
- LockWorld( TRUE);
-
- SetGDevice( worldDevice);
- SetPort( worldPort);
- }
- else /* World is black and white */
- {
- GetPort( &savePort);
- SetPort( macPort);
- }
- }
-
-
- /******************************************************************************
- DeactivateWorld
-
- Restores the previously active graphics device and port.
- ******************************************************************************/
-
- void CPixelWorld::DeactivateWorld()
- {
- if (!worldIsOK) return;
-
- if (worldHasColor) /* World has color */
- {
- LockWorld( FALSE);
-
- if (saveDevice != NULL) SetGDevice( saveDevice);
- if (savePort != NULL) SetPort( savePort);
-
- saveDevice = NULL;
- savePort = NULL;
- }
- else
- {
- if (savePort != NULL) SetPort( savePort);
- savePort = NULL;
- }
- }
-
-
- /******************************************************************************
- LockWorld
-
- Lock or unlock the worldPixels handle according to the flag setLock.
- If setLock is true, then the worldPixels handle is locked and the
- de-referenced handle is put into the baseAddr field of worldDevice
- and worldPort PixMap structures.
- ******************************************************************************/
-
- Boolean CPixelWorld::LockWorld(
- Boolean setLock)
- {
- if (!worldIsOK) return (FALSE);
-
- if (worldHasColor)
- {
- if (worldPixelsLocked)
- {
- if (!setLock)
- {
- PixMapHandle hMap;
-
- HUnlock(worldPixels);
-
- hMap = (**worldDevice).gdPMap;
- (**hMap).baseAddr = NULL;
-
- hMap = worldPort->portPixMap;
- (**hMap).baseAddr = NULL;
-
- worldPixelsLocked = FALSE;
- }
-
- return (TRUE);
- }
- else
- {
- if (setLock)
- {
- PixMapHandle hMap;
-
- MoveHHi(worldPixels);
- HLock(worldPixels);
-
- hMap = (**worldDevice).gdPMap;
- (**hMap).baseAddr = (Ptr) *worldPixels;
-
- hMap = worldPort->portPixMap;
- (**hMap).baseAddr = (Ptr) *worldPixels;
-
- worldPixelsLocked = TRUE;
- }
-
- return (FALSE);
- }
- }
-
- return (FALSE);
- }
-
-
- /******************************************************************************
- SaveColors
-
- Save the current foreground and background colors.
- ******************************************************************************/
-
- void CPixelWorld::SaveColors()
- {
- RGBColor color;
-
- GetForeColor( &color);
- saveFgColor = color;
-
- GetBackColor( &color);
- saveBgColor = color;
- }
-
-
- /******************************************************************************
- RestoreColors
-
- Restore the original foreground and background colors.
- ******************************************************************************/
-
- void CPixelWorld::RestoreColors()
- {
- RGBColor color;
-
- color = saveFgColor;
- RGBForeColor( &color);
-
- color = saveBgColor;
- RGBBackColor( &color);
- }
-
-
- /******************************************************************************
- CopyFromColors
-
- The CopyFrom() method calls this routine to set the foreground
- and background colors just before calling CopyBits. By setting
- the foreground to BLACK and the background to WHITE, this method
- ensures that the image is copied without colorization. This means
- that the colors of the original image and the copy will match.
-
- If you want to colorize the copy of the image so its colors are
- different from the original, create a subclass in which you override
- this method and set the foregound and background colors appropriately.
- ******************************************************************************/
-
- void CPixelWorld::CopyFromColors()
- {
- RGBColor color;
-
- /* Black foreground */
- color.red = color.green = color.blue = 0x0000;
- RGBForeColor( &color);
-
- /* White background */
- color.red = color.green = color.blue = 0xFFFF;
- RGBBackColor( &color);
- }
-
-
- /******************************************************************************
- CopyToColors
-
- The CopyTo() method calls this routine to set the foreground
- and background colors just before calling CopyBits. By setting
- the foreground to BLACK and the background to WHITE, this method
- ensures that the image is copied without colorization. This means
- that the colors of the original image and the copy will match.
-
- If you want to colorize the copy of the image so its colors are
- different from the original, create a subclass in which you override
- this method and set the foregound and background colors appropriately.
- ******************************************************************************/
-
- void CPixelWorld::CopyToColors()
- {
- RGBColor color;
-
- /* Black foreground */
- color.red = color.green = color.blue = 0x0000;
- RGBForeColor( &color);
-
- /* White background */
- color.red = color.green = color.blue = 0xFFFF;
- RGBBackColor( &color);
- }
-
-
- /******************************************************************************
- CopyFrom {OVERRIDE}
-
- Copy bits from a PixelWorld to the bit map of the current port. The
- fromRect is a rectangle in this PixelWorld (source rect), and the
- toRect is a rectangle in the current port's bit map (dest rect).
- maskRgn is a clipping region specified in the same coords as the
- dest rect, i.e., the coords of the current port. A NULL maskRgn means
- that no extra clipping is performed. Copying takes place using the
- transfer mode stored in the xferMode instance variable.
- ******************************************************************************/
-
- void CPixelWorld::CopyFrom(
- LongRect *fromRect,
- LongRect *toRect,
- RgnHandle maskRgn)
- {
- if (!worldIsOK) return;
-
- if (worldHasColor) /* World has color */
- {
- Boolean savedLock;
-
- SaveColors();
- CopyFromColors();
- savedLock = LockWorld( TRUE);
-
- LCopyBits( &((GrafPtr)worldPort)->portBits, &thePort->portBits,
- fromRect, toRect, xferMode, maskRgn);
-
- LockWorld( savedLock);
- RestoreColors();
- }
- else /* World is black and white */
- { /* Call the inherited method */
- inherited::CopyFrom( fromRect, toRect, maskRgn);
- }
- }
-
-
- /******************************************************************************
- CopyTo {OVERRIDE}
-
- Copy bits to a PixelWorld from the bit map of the current port. The
- fromRect is a rectangle in the current port's bit map (source rect),
- and the toRect is a rectangle in this PixelWorld (dest rect). maskRgn is
- a clipping region specified in the same coords as the dest rect,
- i.e., the coords of this PixelWorld. A NULL maskRgn means that no extra
- clipping is performed. Copying takes place using the transfer mode
- stored in the xferMode instance variable.
- ******************************************************************************/
-
- void CPixelWorld::CopyTo(
- LongRect *fromRect,
- LongRect *toRect,
- RgnHandle maskRgn)
- {
- if (!worldIsOK) return;
-
- if (worldHasColor) /* World has color */
- {
- Boolean savedLock;
-
- SaveColors();
- CopyToColors();
- savedLock = LockWorld( TRUE);
-
- LCopyBits( &thePort->portBits, &((GrafPtr)worldPort)->portBits,
- fromRect, toRect, xferMode, maskRgn);
-
- LockWorld( savedLock);
- RestoreColors();
- }
- else /* World is black and white */
- { /* Call the inherited method */
- inherited::CopyTo( fromRect, toRect, maskRgn);
- }
- }
-
-
-